﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using Helper;

namespace DAL
{
    public class Menu_l2DAL
    {
        //---------------------Menu_l2SearchById-----------------------------
        public List<objMenu_l2> Menu_l2SearchById(int id)
        {

            List<objMenu_l2> lst = new List<objMenu_l2>();

            objMenu_l2 obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l2SearchById", parameterList);
            while (dr.Read())
            {
                obj = new objMenu_l2();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Id_l1 = int.Parse(dr["id_l1"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------Menu_l2SearchById_l1-----------------------------
        public List<objMenu_l2> Menu_l2SearchById_l1(int id_l1)
        {

            List<objMenu_l2> lst = new List<objMenu_l2>();

            objMenu_l2 obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_l1", id_l1));


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l2SearchById_l1", parameterList);
            while (dr.Read())
            {
                obj = new objMenu_l2();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Id_l1 = int.Parse(dr["id_l1"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------Menu_l2Insert-----------------------------
        public int Menu_l2Insert(int id_l1, string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_l1", id_l1));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l2Insert", parameterList);

            return i;
        }

        //---------------------Menu_l2Update-----------------------------
        public int Menu_l2Update(int id, int id_l1, string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@id_l1", id_l1));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l2Update", parameterList);

            return i;
        }

        //---------------------Menu_l2Delete-----------------------------
        public int Menu_l2Delete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l2Delete", parameterList);

            return i;
        }
    }
}
